package com.gizwits.util

import org.apache.commons.codec.binary.{Hex, Base64}
object CommonUtil {
   def base64hexString(s:String):String=Hex.encodeHexString(Base64.decodeBase64(s))
   def get_msg_len(data:Array[Byte]):(Int,Int) = {
      import scala.util.control.Breaks._
      var ret = 0;
      var len = 0;
      breakable {for {i <- 0 to 3} {
         ret += (data(4+i) & 0x7F) << (7 * i)
         len = i+1
         if ((data(4+i) & 0x80) == 0) {
            break
         }
      }}

     var sn_code_len = 0
     //0x91
     if(data(len+6) == 0x91.asInstanceOf[Byte]){
       sn_code_len = 0
      // println("----")
       //0x93 and 0x94 多了4个byte 的sn码
     }else if(data(len+6) == 0x93.asInstanceOf[Byte] || data(len+6) == 0x94.asInstanceOf[Byte]) {
       sn_code_len = 4
     }
      (len,ret-4-sn_code_len)
   }

  def  parseBson(json:String)=org.bson.BsonDocument.parse(json)
}
